package com.nyz.huawei.model;


import lombok.Data;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Data
public class CreateAssetByFileReq {

    //自动发布任务，创建一个计划执行任务，每隔10分钟检查是否需要发布
    ScheduledExecutorService FBexecutor = Executors.newSingleThreadScheduledExecutor();
    //自动预热任务，创建一个计划执行任务，每隔10分钟检查是否需要预热到CDN
    ScheduledExecutorService YRexecutor = Executors.newSingleThreadScheduledExecutor();
    private int categoryId;
    private String title;
    private String Description;
    private String VideoName;
    private String VideoType;
    private Integer autoPublish;
    private int autoPreheat;
    private int autoEncrypt;

    /**
     * 设置媒资分类Id
     *
     * @param categoryId
     */
    public void setCategoryId(int categoryId) {
        if (categoryId <= 0) { // 确保不仅检查负数，也检查零
            throw new IllegalArgumentException("媒资分类Id不能为负或零！传入值为: " + categoryId);
        }
        this.categoryId = categoryId;
    }

    /**
     * 设置媒资标题
     *
     * @param titleToSet
     */
    public void setTitle(String titleToSet) {
        // 验证参数是否为空或空字符串
        if (titleToSet != null && !titleToSet.isEmpty()) {
            // 正确设置标题的逻辑，这里假设直接赋值给类内部的title属性
            this.title = titleToSet;
        } else {
            // 抛出异常时，提供足够的信息帮助定位问题
            throw new IllegalArgumentException("传入的标题参数为空或为空字符串！");
        }
    }

    /**
     * 设置视频描述
     *
     * @param newDescription
     */
    public void setDescription(String newDescription) {
        if (newDescription != null) {
            this.Description = newDescription;
        } else {
            this.setDescription("");
        }
    }

    /**
     * 设置音视频文件名
     *
     * @param newVideoName
     */
    public void setVideoName(String newVideoName) {
        if (!newVideoName.isEmpty()) {
            this.VideoName = newVideoName;
        } else {
            throw new IllegalArgumentException("音视频文件名为空！");
        }
    }

    /**
     * 设置音视频文件格式
     *
     * @param newVideoType
     */
    public void setVideoType(String newVideoType) {
        if (isValidVideoType(newVideoType)) {
            this.VideoType = newVideoType;
        } else {
            throw new IllegalArgumentException("请设置正确的文件格式");
        }
    }

    private boolean isValidVideoType(String type) {
        //设置视频文件类型,当前支持：MP4、TS、MOV、MXF、MPG、FLV注意大写
        return !type.isEmpty() && type.matches("(MP4|TS|MOV|MXF|MPG|FLV)");
    }

    /**
     * 设置是否自动发布
     *
     * @param autoPublish
     */
    public void setAutoPublish(Integer autoPublish) {
        //“0”表示不自动发布，“1”表示自动发布
        this.autoPublish = 1;
        if (autoPublish == 1) {
            startAutoPublish();
        } else {
            stopAutoPublish();
        }
    }

    private void startAutoPublish() {
        long AUTO_PUBLISH_INTERVAL_MINUTES = 10;
        FBexecutor.scheduleAtFixedRate(new Runnable() {
            //发布任务的具体实现
            public void run() {

            }
        }, 0, AUTO_PUBLISH_INTERVAL_MINUTES, TimeUnit.MINUTES);
    }

    //不自动发布任务
    private void stopAutoPublish() {
        //判断是否为空，如果为空则关闭自动发布任务
        if (FBexecutor != null) {
            FBexecutor.shutdownNow();
        }
    }

    /**
     * 设置是否自动预热到CDN
     *
     * @param autoPreheat
     */
    public void setAutoPreheat(Integer autoPreheat) {
        //“0”表示不自动预热，“1”表示自动预热
        this.autoPreheat = 0;
        if (autoPreheat == 1) {
            startAutoPreheat();
        } else {
            stopAutoPreheat();
        }
    }

    //开启自动预热到CDN
    private void startAutoPreheat() {
        //创建一个定时任务，每隔10分钟预热一次
        long AUTO_PREHEAT_INTERVAL_MINUTES = 10;
        YRexecutor.scheduleAtFixedRate(new Runnable() {
            //预热任务的具体实现
            public void run() {

            }
        }, 0, AUTO_PREHEAT_INTERVAL_MINUTES, TimeUnit.MINUTES);
    }

    //不进行自动预热到CDN
    private void stopAutoPreheat() {
        //判断是否为空，如果为空则关闭自动预热
        if (YRexecutor != null) {
            YRexecutor.shutdownNow();
        }
    }


    public void setVideoSize(int i) {

    }

    /**
     * 设置是否自动加密(加密与转码必须要一起进行，当需要加密时，转码参数不能为空，且转码输出格式必须要为HLS)
     *
     * @param autoEncrypt
     */
    public void setAutoEncrypt(Integer autoEncrypt) {
        this.autoEncrypt = 1;
        if (autoEncrypt == 1) {

        } else {

        }
    }

    /**
     * 设置转码模板组名称
     *
     * @param systemTemplateGroup
     */
    public void setTemplateGroupName(String systemTemplateGroup) {

    }

    public void setReview(Review review) {

    }

    public void setCoverId(int i) {

    }

    public void setVideoFileUrl(String s) {

    }
}
